/**
 * 
 */
package model;

import controller.Controller;

/**
 * @author Bill
 *
 */
public class AttackStageState extends State {

	public AttackStageState(){
	}
	
	void pauseButtonPressed(GameDriver d){
		d.setCurrentState(GameDriver.pauseMenuState);
	}

	@Override
	void advanceState(GameDriver d) {
		boolean gameNotOver = true;
		if(d.getCurrentWave() >= GameDriver.WAVES_PER_LEVEL-1){
			gameNotOver = d.advanceToNextLevel();
			d.setCurrentWave(-1);
		}
		if(gameNotOver){
			d.setCurrentState(GameDriver.setupStageState);
			d.incrementWave();
			Controller.updateView();
			if(d.getCurrentWave() != 0){
				String waveMessage = d.getMap().getCurrentWave().getWaveDescription();
				int waveMessageDuration = d.getMap().getCurrentWave().getWaveDescriptionDuration();
				if(waveMessage.length() >0) Controller.displayHighPriorityMessage(waveMessage, waveMessageDuration);
			}
		}	
	}

	@Override
	void returnToMainMenu(GameDriver d) {
		int level = d.getCurrentLevel();
		int startingPoints = Math.max(d.getPlayer().getPoints(), GameDriver.START_POINTS);
		d.setPlayer(new Player(startingPoints, GameDriver.getStartHealth())); //initialize a player with default start values
		d.setMap(new Map(level, d.getPlayer())); //make a new map starting at the level that you died on
		d.setCurrentWave(0);
		d.setCurrentLevel(level);
		d.setStore(new Store( d.getPlayer() , d.getMap()));
		d.setCurrentState(GameDriver.mainMenuState);
		Controller.createNewMapView(d);
	}

	@Override
	public String getStateName() {
		return "ATTACK_STAGE_STATE";
	}

}
